<?php
if ($this->allowAjaxAssign)
{
    $cs = Yii::app()->clientScript;

    $script = "
    jQuery.assign_timer = null;
    jQuery('.role').click(function(){
        if (jQuery.assign_timer != null)
        {
            clearTimeout(jQuery.assign_timer);
            jQuery('#assign-message').hide();
        }
        var url = '".$this->controller->createUrl('/Core/service/ajax', array('SID'=>'Admin.permission.updateAssign', 'userId'=>$this->userId))."';
        var assign = jQuery(this).attr('checked') ? 1 : 0;
        var role = jQuery(this).val();
        jQuery.get(url, {assign : assign, role : role}, function(){
            jQuery('#assign-message').show();
            jQuery.assign_timer = setTimeout(function(){            
                jQuery('#assign-message').hide();
                clearTimeout(jQuery.assign_timer);
            }, 3000);
        });
    });
    ";
    $cs->registerScript(__CLASS__.'#Assign', $script);
}

echo CHtml::checkBoxList('roles', $assigned, $roles, array('class'=>'role'));

if ($this->allowAjaxAssign) echo '<p id="assign-message" style="display:none">Assign user to role successfully.</p>';
